package com.chenl.provider.DEMOS.WebService;

import com.alibaba.fastjson.JSONObject;
import com.chenl.provider.DEMOS.WebService.参考.GetWSByAxis2;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

public class WebServiceUtil {
    /**
     *
     * @param url 路径
     * @param operationName 方法名称
     * @param params xml入参请求参数
     * @return
     * @throws Exception
     */
    public static String sendWebService(String url, String operationName, String... params) throws Exception {
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient(url);
        Object[] objects;
        objects = client.invoke(operationName, params);
        return JSONObject.toJSONString(objects[0]);
    }

    public static String sendWebServiceByAxis(String url, String operationName, String... params) throws Exception {
        GetWSByAxis2 ws=new GetWSByAxis2();
        ws.WSUrl=url;
        Object result = ws.getStr(operationName, params);
        return JSONObject.toJSONString(result);
    }
}
